package cn.longge.mapper;

import cn.longge.entity.QualificationCondition;
import org.springframework.util.StringUtils;

public class QualificationSqlProvider {

    public String selectByCondition(QualificationCondition qc){
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT\n" +
                "q.id,\n" +
                "q.create_date,\n" +
                "q.type,\n" +
                "q.upload_user_id,\n" +
                "q.`check`,\n" +
                "q.description,\n" +
                "q.check_user_id,\n" +
                "q.update_date,\n" +
                "uu.name as upload_user_name,\n" +
                "cu.name as check_user_name\n" +
                "FROM\n" +
                "qualification q \n" +
                "left join \n" +
                "sys_user uu \n" +
                "on q.upload_user_id = uu.id \n" +
                "left join \n" +
                "sys_user cu \n" +
                "on q.check_user_id = cu.id\n" +
                "where q.del_flag = 0 ");
        if(!StringUtils.isEmpty(qc.getFromTime())){
            sb.append(" and q.create_date >= #{fromTime} ");
        }
        if(!StringUtils.isEmpty(qc.getToTime())){
            sb.append(" and q.create_date <= #{toTime}");
        }
        if(null != qc.getType()){
            sb.append(" and q.type = #{type} ");
        }
        if(null != qc.getStatus()){
            sb.append(" and q.check = #{status} ");
        }
        return sb.toString();

    }

}
